<!DOCTYPE html>
<!--[if IE 8]> <html  class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html  class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html class="no-js">
<!--<![endif]-->
<head>
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta content="width=device-width, initial-scale=1.0" name="viewport"/>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <link rel="stylesheet" type="text/css" href="${jpath}/assets/public/css/bootstrap.min.css"/>
    <link rel="stylesheet" type="text/css" href="${jpath}/assets/public/font-awesome/css/font-awesome.min.css"/>
    <link rel="stylesheet" type="text/css" href="${jpath}/assets/public/css/public.css"/>
    <!-- ztree-->
    <link href="${jpath}/assets/public/plugins/jquery-ztree/3.5.12/css/zTreeStyle/zTreeStyle.min.css"
          rel="stylesheet"
          type="text/css"/>
    <link href="${jpath}/assets/public/plugins/jqGrid/css/ui.jqgrid-bootstrap.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div class="container-fluid">
    <div class="row">
        <div class="col-xs-12" style="overflow: auto;height:400px; ">
            <div class="col-xs-4">
                <div id="ztree" class="ztree"></div>
            </div>
            <div class=" col-xs-8 ">
                <table id="jqGrid" class="table table-striped table-bordered table-hover"></table>
                <div id="jqGridPager"></div>
            </div>
        </div>
    </div>
</div>
<div class="row navbar-fixed-bottom">
    <div class="col-xs-12 text-center">
        <input type="button" class="btn btn-info btn-sm" value="确定" onclick="doInfo()"/>
        <input type="button" class="btn btn-cancle  btn-sm" value="关闭" onclick=" top.$.bootbox.hideAll();"/>
    </div>
</div>
</body>



<script src="${jpath}/assets/public/js/jquery.min.js"></script>
<script src="${jpath}/assets/public/js/bootstrap.min.js"></script>
<script src="${jpath}/assets/public/js/public.js"></script>
<script src="${jpath}/assets/public/js/jQuery.resizeEnd.min.js"></script>
<script src="${jpath}/assets/public/js/html5shiv.min.js"></script>
<script src="${jpath}/assets/public/js/respond.min.js"></script>
<!-- ztree-->
<script type="text/javascript"
        src="${jpath}/assets/public/plugins/jquery-ztree/3.5.12/js/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="${jpath}/assets/public/plugins/jqGrid/i18n/grid.locale-cn.js"></script>
<script type="text/javascript" src="${jpath}/assets/public/plugins/jqGrid/jquery.jqGrid.min.js"></script>
<script type="text/javascript" src="${jpath}/assets/public/plugins/jqGrid/jqGrid-extends.js"></script>
<script type="text/javascript">

    //ztree
    var setting = {
        callback: {
            onClick: function (event, treeId, treeNode) {
                var code = treeNode.code;
                var url;
                if (!code) {
                    return;
                }
                if (treeNode.isParent) {
                    url =  "${base}/account/view/list?companyCode=" + code;

                }
                if (!treeNode.isParent) {
                    url =  "${base}/account/view/list?orgCode=" + code;
                }
                if (!url) {
                    return;
                }
                $("#jqGrid").jqGrid('setGridParam', {url: url}).trigger("reloadGrid");
            }
        },
        async: {
            type: 'post',
            enable: true,
            url: "${base}/organization/view/treeData"
        }
    };

    function refreshTree() {
        $.fn.zTree.init($("#ztree"), setting, null)
    }


    function loadTreeTable() {
        $("#jqGrid").jqGrid({
            url:  '${base}/account/view/list',
            datatype: "json",
            styleUI: 'Bootstrap',
            colModel: [
                {
                    name: 'name', label: '用户名', formatter: function (value, options, rData) {
                    return '<a onclick=back(\'' + rData.id + '\',\'' + rData.name + '\')>' + value + '</a>';
                }
                },
                {name: 'loginName', label: '登录名'}
            ],
            width: "370",
            height: 'auto',
            rowNum: 8,
            pager: "#jqGridPager"
        });

    }
    function back(id, name) {
        var idField = tools.getQueryString('idField');
        var textField = tools.getQueryString('textField');
        var fn = tools.getQueryString('fn');
        if (typeof fn == 'function') {
            eval("top." + fn + "(" + id + "," + name + ")");
        } else {
            var contentFrame=tools.getCurrentFrame();
            if(contentFrame){
                var contentFrameDoc=contentFrame.document;
                $("#" + idField, contentFrameDoc).val(id);
                $("#" + textField, contentFrameDoc).val(name);
            }
            else{
                $("#" + idField, top.window.document).val(id);
                $("#" + textField, top.window.document).val(name);
            }
            top.$.bootbox.hideAll();
        }
    }

    function doInfo(){
       var rowid=$("#jqGrid").getGridParam("selrow");//获得选中id;
        if(rowid){
            var name = $("#" + rowid).find("td a").html();//获得被选中行的name
            back(rowid,name);
        }
        else{
            top.$.bootbox.hideAll();
        }
    }


    $(function () {
        refreshTree();
        loadTreeTable();
    });
</script>
</html>